package com.hongsen.cn.Utils;

import android.graphics.Rect;
import android.view.View;

import androidx.recyclerview.widget.RecyclerView;


public class GridSpacingItemDecoration extends RecyclerView.ItemDecoration {
    private int space;
    private int column;

    public GridSpacingItemDecoration(int space, int column) {
        this.space = space;
        this.column = column;
    }

    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
        outRect.top = space;

        if (parent.getChildLayoutPosition(view) % column == 0) {
            outRect.left = space;
            outRect.right = space / 2;
        } else if (parent.getChildLayoutPosition(view) % column == column - 1) {
            outRect.left = space / 2;
            outRect.right = space;
        } else {
            outRect.left = space / 2;
            outRect.right = space / 2;
        }
    }
}